package org.setec.utils.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;

public class Stub implements Serializable {

    private Object[] args;
    private Object result;
    private String className;
    private String methodName;

    public Stub(File file) throws Throwable {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(file));
        Stub stub = (Stub)objectInputStream.readObject();
        this.args = stub.args;
        this.result = stub.result;
        this.className = stub.className;
        this.methodName = stub.methodName;
    }

    public Stub(String className, String methodName, Object[] args, Object result){
        this.args = args;
        this.result = result;
        this.className = className;
        this.methodName = methodName;
    }

    public Object[] getArgs() {
        return args;
    }

    public void setArgs(Object[] args) {
        this.args = args;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public boolean equalInput(Stub stub){
        boolean result = true;
        result &= stub.className.equals(className);
        result &= stub.methodName.equals(methodName);
        for( int i = 0; i<args.length; i++ ){
            result &= stub.args[i].getClass().getName().equals(args[i].getClass().getName());
        }
        return result;
    }
}
